import type { IUpdatePassword } from '@/views/updatePassword/UpdatePassword.vue'
import type { IUserInfo } from '@/views/updateUserInfo/UpdateUserInfo.vue'
import Http from './axios'
import type { ISearchParams } from '@/views/userManage/index.vue'
import type { SearchMeetingRoom } from '@/views/meetingRoomManage/index.vue'
import type { IMeetingRoomFormData } from '@/views/meetingRoomManage/CreateMeetingRoomModal.vue'
import type { SearchBookingList } from '@/views/bookingManage/index.vue'

export async function login(username: string, password: string) {
  return await Http.post('/user/admin/login', {
    username,
    password
  })
}

export async function updatePasswordCaptcha(email: string) {
  return await Http.get('/user/update_password/captcha', {
    params: {
      address: email
    }
  })
}
export async function updatePassword(data: IUpdatePassword) {
  return await Http.post('/user/admin/update_password', data)
}

export async function getUserInfo() {
  return await Http.get('/user/info')
}

export async function updateUserInfo(data: IUserInfo) {
  return await Http.post('/user/admin/update', data)
}

export async function updateUserInfoCaptcha() {
  return await Http.get('/user/update/captcha')
}

export async function queryUserList(condition: ISearchParams) {
  return await Http.get('/user/list', {
    params: {
      ...condition
    }
  })
}

export async function freeze(id: number) {
  return await Http.get('/user/freeze', {
    params: {
      id
    }
  })
}

export const meetingRoomList = async (condition: SearchMeetingRoom) => {
  return Http.get('/meeting-room/list', {
    params: {
      ...condition
    }
  })
}

export const deleteMeetingRoom = async (id: number) => {
  return Http.delete(`/meeting-room/${id}`)
}

export const createMeetingRoom = async (condition: IMeetingRoomFormData) => {
  return Http.post('/meeting-room/create', condition)
}

export const updateMeetingRoom = async (condition: IMeetingRoomFormData) => {
  return Http.post('/meeting-room/update', condition)
}

export const getBookingList = async (condition: SearchBookingList) => {
  return await Http.get('/booking/list', {
    params: {
      ...condition
    }
  })
}

export const apply = async (id: number) => {
  return await Http.get(`/booking/apply/${id}`)
}
export const reject = async (id: number) => {
  return await Http.get(`/booking/reject/${id}`)
}
export const unbind = async (id: number) => {
  return await Http.get(`/booking/unbind/${id}`)
}

export const userBookingCount = async (startTime: string, endTime: string) => {
  return await Http.get('/statistic/userBookingCount', {
    params: {
      startTime,
      endTime
    }
  })
}
export const meetingRoomUsedCount = async (startTime: string, endTime: string) => {
  return await Http.get('/statistic/meetingRoomUsedCount', {
    params: {
      startTime,
      endTime
    }
  })
}
export async function presignedUrl(fileName: string) {
  return Http.get(`/minio/presignedUrl?name=${fileName}`)
}

export async function uploadFile(formData: FormData) {
  return Http.post('/user/upload', formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
